﻿@using System.Text.RegularExpressions
@using BXJG.Common.Events
@inherits LayoutComponentBase
@inject NavigationManager Navigation
@implements IDisposable

<HeadContent>

    <link antblazor-css>
    <link href="@Assets["app.css"]" rel="stylesheet" />
</HeadContent>

   <MyPageTitle  />

<div style="height:100vh">
    <ErrorBoundary @ref="errorBoundary">
        <ChildContent>

            <Layout>
                <Sider @bind-Collapsed=@MainMenuCollapsed NoTrigger Collapsible>
                    <div class="logo" style="height:29px; margin:15px;">
                        <img src="bxjglogo.png" style="width:37px; height:30px; float:left;" />

                        @if (!MainMenuCollapsed)
                        {
                            <h3 style="    color: #ddd;    float: left;    margin-left: 0.5rem;    line-height: 35px;    font-size: 1.2rem;">
                                变形精怪
                            </h3>
                        }
                    </div>
                    @* 菜单需要交互式 *@
                    <MainMenu Collapsed=MainMenuCollapsed />
                </Sider>
                <Layout>
                    <Header Class="zlj-main-head">
                        <Flex Gap="FlexGap.Small" Vertical=false Justify="FlexJustify.SpaceBetween" Align="FlexAlign.Center" Style="height:100%;">
                            @* 左边 *@
                            <Flex Gap="FlexGap.Small" Vertical=false Align="FlexAlign.Center">
                                @if (MainMenuCollapsed)
                                {
                                    <Icon Type="menu-unfold" Theme="IconThemeType.Outline" Class="caidan-kaiguan" OnClick="toggle" />
                                }
                                else
                                {
                                    <Icon Type="menu-fold" Theme="IconThemeType.Outline" Class="caidan-kaiguan" OnClick="toggle" />
                                }
                                @* <MainBreadcrumb style="padding-left:1rem;" /> *@
                            </Flex>
                            @* 右边 *@
                            <HeaderRight />
                        </Flex>
                    </Header>
                    <Content Style="padding-bottom:2.7vh;">
                        @if (auth)
                        {
                            <ReuseTabs Class="zlj-main-body-box" TabPaneClass="zlj-main-tab-head-item" />
                        }
                        else
                        {
                            <div class="zlj-main-body-box-no-auth">@Body</div>
                        }
                    </Content>
                    <Footer Style="text-align: center; padding:0.3rem 0; color:rgba(100,100,100,0.7); height:3.5vh; position:fixed; z-index:999; width:100%; bottom:0;">
                        Copyright ©1900-2024 变形精怪, All Rights Reserved | Power by <a href="https://dotnet.microsoft.com/zh-cn/apps/aspnet" target="_blank">asp.net @System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription</a> / <a href="https://aspnetboilerplate.com" target="_blank">abp @typeof(Abp.AbpBootstrapper).Assembly.GetName().Version</a> / <a href="https://antblazor.com" target="_blank">antblazor @typeof(AntDesign.AntComponentBase).Assembly.GetName().Version</a> / <a href="https://gitee.com/bxjg1987_admin/abp" target="_blank">源码</a>
                    </Footer>
                </Layout>
            </Layout>


        </ChildContent>
        <ErrorContent>
            <Flex Gap="FlexGap.Small" Style="height:50vh;" Align="FlexAlign.Center" Justify="FlexJustify.Center" Vertical="true">
                <div>
                    ┗|｀O′|┛ 嗷~~程序出错啦！若多次输出错，请联系系统管理员。 <br />
                </div>
                <pre>   @XianshiCuowu(context) </pre>


                <Button Type="@ButtonType.Primary" OnClick="fanhui">返回</Button>
            </Flex>
        </ErrorContent>
    </ErrorBoundary>


</div>


<SectionContent SectionName="bottom-scripts">
    <script antblazor-js></script>
    <script src="/echarts.5.4.3.min.js"></script>
    <script type="module" src="_content/Blazor.ECharts/core.js"></script>
    <script>
        // import { BrotliDecode } from '/decode.min.js';
        // Blazor.start({
        //     webAssembly: {
        //         loadBootResource: function (type, name, defaultUri, integrity) {
        //             if (type !== 'dotnetjs' && location.hostname !== 'localhost' && type !== 'configuration' && type !== 'manifest') {
        //                 return (async function () {
        //                     const response = await fetch(defaultUri + '.br', { cache: 'no-cache' });
        //                     if (!response.ok) {
        //                         throw new Error(response.statusText);
        //                     }
        //                     const originalResponseBuffer = await response.arrayBuffer();
        //                     const originalResponseArray = new Int8Array(originalResponseBuffer);
        //                     const decompressedResponseArray = BrotliDecode(originalResponseArray);
        //                     const contentType = type ===
        //                         'dotnetwasm' ? 'application/wasm' : 'application/octet-stream';
        //                     return new Response(decompressedResponseArray,
        //                         { headers: { 'content-type': contentType } });
        //                 })();
        //             }
        //         }
        //     }
        // });
        //https://github.com/dotnet/aspnetcore/pull/53291
        //注意上面的blazor.web.js autostart="false"
        //经过测试，下面的测试没什么卵用
        // Blazor.start({
        //     webAssembly: {
        //         configureRuntime: (builder) => {
        //             builder.withConfig({
        //                 maxParallelDownloads: 1
        //             });
        //         },
        //     },
        // });
    </script>
</SectionContent>

@code {
    // [SupplyParameterFromQuery]
    // public int mmc { get; set; }

    string XianshiCuowu(Exception ex)
    {
#if DEBUG
    return ex.GetBaseException().StackTrace + Environment.NewLine;
#else
        return Environment.NewLine;
#endif

    }

    // bool collapsed => mmc > 0;
    bool auth = false;
    private ErrorBoundary? errorBoundary;
    [Inject]
    public AuthenticationStateProvider AuthStateProvider { get; set; }
    [Inject]
    public Zhongjie Zhongjie { get; set; }

    bool MainMenuCollapsed;
    [Inject]
    public ILogger<StaticLayout> Logger { get; set; }
    //string LayoutStyle => "background-color:#f3f6fb; margin-left:" + (MainMenuCollapsed ? 80 : 200) + "px;transition-property: margin-left";
    void fanhui()
    {
        errorBoundary?.Recover();
    }
    void fancuo()
    {

        throw new Exception("xxxxxxxxxxxxxxx");
    }
    void toggle()
    {
        MainMenuCollapsed = !MainMenuCollapsed;
    }
    // IDisposable appContainerInited;
    protected override void OnInitialized()
    {
        // appContainerInited = Zhongjie.Zhuce( async () =>
        // {
        //     appContainerInited?.Dispose();
        //     this.Logger.LogDebug("全局状态初始化处理事件执行！");
        //     StateHasChanged();
        //     await InvokeAsync(StateHasChanged);

        // },"appContainerInited");
        base.OnInitialized();
    }
    public void Dispose()
    {
        // appContainerInited?.Dispose();
    }

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        var zt = await AuthStateProvider.GetAuthenticationStateAsync();
        auth = zt != null && zt.User != default && zt.User.Identity.IsAuthenticated;

        //  await Task.Delay(5000);
        //  InvokeAsync(StateHasChanged);
        // StateHasChanged();
    }
    // [Inject]
    // public IJSRuntime JSRuntime { get; set; }

    // protected override async Task OnAfterRenderAsync(bool firstRender)
    // {
    //     // if (firstRender)
    //     //{
    //     //Console.WriteLine("xxxxxxxxxxxxxxxxxxxxxxx");
    //     await JSRuntime.InvokeVoidAsync("hideLoadingDiv");
    //     //}
    // }
}